<template>
	<view class="goods-item">
		<view class="goods-item-left">
			<radio v-if="showRadio" :checked="goods.goods_state" color="#C00000" @click='RadioClickHandler'></radio>
			<image class="goods-pic" :src="goods.goods_small_logo || defaultPic"></image>
		</view>
		<view class="goods-item-right">
			<text class="goods-name">{{goods.goods_name}}</text>
			<view class="goods-info-box">
				<text class="goods-price">￥{{goods.goods_price | toFixed}}</text>
				<uni-number-box v-if="showNum" :min="1" :value="goods.goods_count" @change="nubmerChangehandler"></uni-number-box>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		name:"my-goods",
		props: {
			goods: {
				type: Object,
				default: {}
			},
			showRadio: {
				typeof: Boolean,
				default: false
			},
			showNum: {
				type: Boolean,
				default: false
			}
		},
		data() {
			return {
				defaultPic: 'https://img3.doubanio.com/f/movie/8dd0c794499fe925ae2ae89ee30cd225750457b4/pics/movie/celebrity-default-medium.png'
			};
		},
		methods: {
			RadioClickHandler(){
				this.$emit('radio-change',{
					goods_id: this.goods.goods_id,
					goods_state: !this.goods.goods_state
				})
			},
			nubmerChangehandler(NewValue){
				this.$emit('numberChange',{
					goods_id: this.goods.goods_id,
					goods_count: NewValue
				})
			}
		},
		filters: {
			toFixed(num){
				return Number(num).toFixed(2)
			}
		}
	}
</script>

<style lang="scss">
.goods-item{
	width: 750rpx;
	box-sizing: border-box;
	display: flex;
	border-bottom: 1px solid #f0f0f0;
	padding: 10px 5px;
	.goods-item-left{
		margin-right: 5px;
		display: flex;
		align-items: center;
		justify-content: space-between;
		radio{
			
		}
		.goods-pic{
			width: 100px;
			height: 100px;
			display: block;
		}
	}
	.goods-item-right{
		display: flex;
		flex-direction: column;
		margin-left: 5px;
		justify-content: space-between;
		flex: 1;
		.goods-name{
			font-size: 13px;
		}
		.goods-info-box{
			display: flex;
			justify-content: space-between;
			align-items: center;
			.goods-price{
				font-size: 16px;
				color: #C00000;
			}
		}
	}
}
</style>